﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutumnEngine;

namespace AutumnEngine.Modules
{
    /// <summary>
    /// Controls scenes within the engine.
    /// </summary>
    public class SceneManagerModule : Module
    {
        Dictionary<string, Scene> scenes;
        /// <summary>
        /// Gets or sets the name of the active scene.
        /// </summary>
        /// <value>The name of the active scene.</value>
        public string ActiveSceneName
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the active scene.
        /// </summary>
        /// <value>The active scene.</value>
        public Scene ActiveScene
        {
            get { return scenes[ActiveSceneName]; }
        }

        public Dictionary<string, Scene> Scenes
        {
            get { return scenes; }
        }
        /// <summary>
        /// Creates this instance.
        /// </summary>
        public override void Create()
        {
            scenes = new Dictionary<string, Scene>();
            scenes.Add("", new Scene());
            ActiveSceneName = "";
            this.Removable = false;
            this.CanBeDisabled = false;
            base.Create();
        }

        /// <summary>
        /// Adds the scene.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="scene">The scene.</param>
        public void AddScene(string name, Scene scene)
        {
            if (Engine.Modules.Contains("Engine.Logging"))
                Engine.Modules.Logging.Write("Adding scene " + name, LogLevel.Debug);
            scene.OnAdd(name);
            scenes.Add(name, scene);
           
            //if we haven't got an active scene, set it to the first added.
            if (ActiveSceneName == "")
                ActiveSceneName = name;

        }

        /// <summary>
        /// Draws this instance.
        /// </summary>
        public override void TranslatedDraw()
        {
            ActiveScene.DrawTranslated();
            base.TranslatedDraw();
        }

        public override void NoneTranslatedDraw()
        {
            ActiveScene.DrawNoneTranslated();
            base.NoneTranslatedDraw();
        }

        /// <summary>
        /// Updates this instance.
        /// </summary>
        public override void Update()
        {
            ActiveScene.Update();
            base.Update();
        }
    }
}
